package com.bcn.login_mybatisplus_demo.record.controller;

import java.util.List;

import com.bcn.login_mybatisplus_demo.common.controller.BaseController;
import com.bcn.login_mybatisplus_demo.common.page.TableDataInfo;
import com.bcn.login_mybatisplus_demo.pojo.vo.R;
import com.bcn.login_mybatisplus_demo.record.domain.TAppRecord;
import com.bcn.login_mybatisplus_demo.record.service.ITAppRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;


/**
 * 人生历程Controller
 * 
 * @author administrator
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/system/record")
public class TAppRecordController extends BaseController
{
    private String prefix = "system/record";

    @Autowired
    private ITAppRecordService tAppRecordService;

    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询人生历程列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TAppRecord tAppRecord)
    {
        startPage();
        List<TAppRecord> list = tAppRecordService.selectTAppRecordList(tAppRecord);
        return getDataTable(list);
    }



    /**
     * 新增人生历程
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存人生历程
     */
    @PostMapping("/add")
    public R addSave(@RequestBody TAppRecord tAppRecord)
    {
        return R.success(tAppRecordService.insertTAppRecord(tAppRecord));
    }

    /**
     * 修改人生历程
     */
    @GetMapping("/edit/{recordId}")
    public String edit(@PathVariable("recordId") Long recordId, ModelMap mmap)
    {
        TAppRecord tAppRecord = tAppRecordService.selectTAppRecordById(recordId);
        mmap.put("tAppRecord", tAppRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存人生历程
     */
    @PostMapping("/edit")
    public R editSave(@RequestBody TAppRecord tAppRecord)
    {
        return R.success(tAppRecordService.updateTAppRecord(tAppRecord));
    }

    /**
     * 删除人生历程
     */

    @GetMapping( "/remove/{id}")
    public R remove(@PathVariable("id") Integer id)
    {
        return R.success(tAppRecordService.deleteTAppRecordById(id.longValue()));
    }
}
